package net.mingsoft.config;

import org.apache.catalina.Context;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TomcatConfig {
    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                // 配置外部目录作为资源根路径（类似 docBase）
                String externalDir = "/opt/apps/mcms/";
                context.setDocBase(externalDir); // 仅对嵌入式 Tomcat 有效，模拟 docBase
                // 可选：添加额外的资源映射（如将 /upload 映射到外部目录）
                context.addWelcomeFile("index.html"); // 设置欢迎页
            }
        };
        return factory;
    }
}